package deck ;
import motion.Actuate;
import openfl.display.Bitmap;
import openfl.display.Sprite;
import openfl.events.MouseEvent;

/**
 * ...
 * @author Marcos Martinez
 */
class Card extends Sprite
{
	private var m_bmRear:Bitmap;
	private var m_bmFront:Bitmap;
	private var m_nWidth:Float;
	private var m_nX:Float;
	public function new(bmFront:Bitmap, bmRear:Bitmap) :Void
	{
		super();
		m_bmRear= bmRear;
		m_bmFront = bmFront;
		m_nWidth = m_bmFront.width;
		this.addChild(m_bmRear);
		this.addChild(m_bmFront);

		this.mouseEnabled = true;
		this.useHandCursor = true;
		this.buttonMode = true;
		
		m_bmFront.visible = true;
		m_bmRear.visible = false;
		this.addEventListener(MouseEvent.CLICK, onClick);
	}
	
	private function onClick(ev:MouseEvent):Void
	{
		//trace("click");
		m_nX = this.x;
		var prop =
		{
			x:m_nX+this.width/2,
			width:0
		};
		Actuate.tween(this, 1, prop ).onComplete(secondPart);
	}
	
	private function secondPart():Void
	{
		var prop =
		{
			x:m_nX,
			width:m_nWidth 
		};
		m_bmFront.visible = !m_bmFront.visible;
		m_bmRear.visible = !m_bmRear.visible;
		Actuate.tween(this, 1, prop );// .onComplete(secondPart);
	}
	

}